/**
 * 
 */
package cn.simonfish.acus.common.data;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @author Simon Yu
 *
 */
public class DataSet {
	
	/**
	 * 
	 */
	private List<String> fields = new ArrayList<String>();
	
	/**
	 * 
	 */
	private List<Map> rows = new ArrayList<Map>();
	
	/**
	 * 
	 */
	private String idField;
	
	
	private int total;
	
	
	/**
	 * @param row
	 */
	public void addRow(Map row){
		rows.add(row);
	}
	
	/**
	 * @param index
	 * @return
	 */
	public Map getRow(int index){
		return rows.get(index);
	}
	
	public void removeAll(){
		rows.clear();
	}
	
	public void remove(int index){
		rows.remove(index);
	}
	
	/**
	 * @param id
	 * @return
	 */
	public Map getRowById(Object id){
		if(id == null){
			return null;
		}
		for (Iterator iter = this.rows.iterator(); iter.hasNext();) {
			Map row = (Map) iter.next();
			if(id.equals(row.get(idField))){
				return row;
			}
		}
		return null;
	}

	/**
	 * @return the rows
	 */
	public List<Map> getRows() {
		return rows;
	}

	/**
	 * @param rows the rows to set
	 */
	public void setRows(List<Map> rows) {
		this.rows = rows;
	}

	/**
	 * @return the fields
	 */
	public List<String> getFields() {
		return fields;
	}

	/**
	 * @param fields the fields to set
	 */
	public void setFields(List<String> fields) {
		this.fields = fields;
	}

	/**
	 * @return the idField
	 */
	public String getIdField() {
		return idField;
	}

	/**
	 * @param idField the idField to set
	 */
	public void setIdField(String idField) {
		this.idField = idField;
	}

	/**
	 * @return the total
	 */
	public int getTotal() {
		return total;
	}

	/**
	 * @param total the total to set
	 */
	public void setTotal(int total) {
		this.total = total;
	}
	

}
